package com.kaiwukj.android.ufamily.mvp.ui.page.service.gm.playback;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.kaiwukj.android.ufamily.R;
import com.kaiwukj.android.ufamily.mvp.http.entity.helper.EzVideoPlaybackEntity;
import com.kaiwukj.android.ufamily.mvp.ui.widget.SpaceItemDecoration;
import com.videogo.openapi.bean.EZDeviceRecordFile;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;

public class PlaybackListParentAdapter extends BaseQuickAdapter<EzVideoPlaybackEntity, BaseViewHolder> {
    public PlaybackListParentAdapter() {
        super(R.layout.item_gm_playback_parent, new ArrayList<>());
    }

    @Override
    protected void convert(@NotNull BaseViewHolder holder, EzVideoPlaybackEntity item) {
        holder.setText(R.id.tv_title, item.getGroupTitle());
        RecyclerView rvList = holder.getView(R.id.rv_child);
        rvList.setLayoutManager(new LinearLayoutManager(getContext()));
        rvList.addItemDecoration(new SpaceItemDecoration(1));
        PlaybackListChildAdapter mChildAdapter = new PlaybackListChildAdapter();
        rvList.setAdapter(mChildAdapter);
        mChildAdapter.setList(item.getResults());

        mChildAdapter.setOnItemClickListener((adapter, view, position) -> {
            if (mListener != null) {
                mListener.onItemClick(position, mChildAdapter.getItem(position));
            }
        });
    }


    private OnItemClickListener mListener;

    public void setItemListener(OnItemClickListener listener) {
        mListener = listener;
    }

    public interface OnItemClickListener {
        void onItemClick(int position, EZDeviceRecordFile file);
    }
}
